package cn.wolfcode.p2p.base.service.impl;

import cn.wolfcode.p2p.base.domain.OrderTime;
import cn.wolfcode.p2p.base.mapper.OrderTimeMapper;
import cn.wolfcode.p2p.base.query.VideoAuthQueryObject;
import cn.wolfcode.p2p.base.service.IOrderTimeService;
import cn.wolfcode.p2p.util.BitStatesUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderTimeServiceImpl implements IOrderTimeService {
    @Autowired
    private OrderTimeMapper orderTimeMapper;
    @Override
    public List<OrderTime> listAll() {
        return orderTimeMapper.selectAll();
    }

    @Override
    public Long getBitState(VideoAuthQueryObject qo) {
        return orderTimeMapper.selectState(qo);
    }

    /**
     * 获取可预约的时间段
     */
    @Override
    public List getAvailableTime(VideoAuthQueryObject qo) {
        List<OrderTime> orderTimes = listAll();
        Long bitState = getBitState(qo);
        if(bitState != null){
            for(int i = 0; i < orderTimes.size();i ++){
                if(BitStatesUtils.hasState(bitState,orderTimes.get(i).getBitState())){
                    orderTimes.remove(i);
                }
            }
        }
        return orderTimes;
    }

}
